home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / cyberxxxsrc / decoder / txt / decodecvid.c < prev    next >
C/C++ Source or Header  |  1999-02-08  |  23KB  |  798 lines

  1. /*
  2. sc:c/sc opt txt/DecodeCVID.c
  3. */
  4.  
  5. #include "Decode.h"
  6. #include "Utils.h"
  7. #include "YUV.h"
  8. #include "GlobalVars.h"
  9.  
  10. /* /// "blockInc" */
  11. #define blockInc(x,y,xmax) {  \
  12.   x+=4;                       \
  13.   if (x>=xmax) { x=0; y+=4; } \
  14. }
  15. /* \\\ */
  16.  
  17. #define cvidMaxStrips 16
  18.  
  19. /* /// "structs" */
  20. struct Color2x2 {
  21.   RGBTriple rgb0, rgb1, rgb2, rgb3;
  22.   ulong clr00, clr01, clr02, clr03;
  23.   ulong clr10, clr11, clr12, clr13;
  24.   ulong clr20, clr21, clr22, clr23;
  25.   ulong clr30, clr31, clr32, clr33;
  26. };
  27.  
  28. struct CVIDData {
  29.   struct Color2x2 *cvidMaps0[cvidMaxStrips];
  30.   struct Color2x2 *cvidMaps1[cvidMaxStrips];
  31.   long cvidVMap0[cvidMaxStrips];
  32.   long cvidVMap1[cvidMaxStrips];
  33. };
  34. /* \\\ */
  35.  
  36. /* /// "proto types" */
  37. void __regargs YUV2x2toRGB(ulong y0, ulong y1, ulong y2, ulong y3, ulong u, ulong v, struct Color2x2 *cmap2x2);
  38. void __regargs Color2x2Blk1RGB(uchar *to, ulong x, ulong y, ulong width, struct Color2x2 *cmap2x2);
  39. void __regargs Color2x2Blk4RGB(uchar *to, ulong x, ulong y, ulong width, struct Color2x2 *cm0, struct Color2x2 *cm1, struct Color2x2 *cm2, struct Color2x2 *cm3);
  40.  
  41. void __regargs YUV2x2toGray(ulong y0, ulong y1, ulong y2, ulong y3, ulong u, ulong v, struct Color2x2 *cmap2x2);
  42. void __regargs Color2x2Blk1Gray(uchar *to, ulong x, ulong y, ulong width, struct Color2x2 *cmap2x2);
  43. void __regargs Color2x2Blk4Gray(uchar *to, ulong x, ulong y, ulong width, struct Color2x2 *cm0, struct Color2x2 *cm1, struct Color2x2 *cm2, struct Color2x2 *cm3);
  44.  
  45. void __regargs YUV2x2to332Dith14(ulong y0, ulong y1, ulong y2, ulong y3, ulong u, ulong v, struct Color2x2 *cmap2x2);
  46. void __regargs YUV2x2to332Dith42(ulong y0, ulong y1, ulong y2, ulong y3, ulong u, ulong v, struct Color2x2 *cmap2x2);
  47. void __regargs Color2x2Blk1332Dith(uchar *to, ulong x, ulong y, ulong width, struct Color2x2 *cmap2x2);
  48. void __regargs Color2x2Blk4332Dith(uchar *to, ulong x, ulong y, ulong width, struct Color2x2 *cm0, struct Color2x2 *cm1, struct Color2x2 *cm2, struct Color2x2 *cm3);
  49. /* \\\ */
  50.  
  51. void __regargs (*yuv2x2_14) (ulong y0, ulong y1, ulong y2, ulong y3, ulong u, ulong v, struct Color2x2 *cmap2x2);
  52. void __regargs (*yuv2x2_42) (ulong y0, ulong y1, ulong y2, ulong y3, ulong u, ulong v, struct Color2x2 *cmap2x2);
  53. void __regargs (*color2x2blk1) (uchar *to, ulong x, ulong y, ulong width, struct Color2x2 *cmap2x2);
  54. void __regargs (*color2x2blk4) (uchar *to, ulong x, ulong y, ulong width, struct Color2x2 *cm0, struct Color2x2 *cm1, struct Color2x2 *cm2, struct Color2x2 *cm3);
  55.  
  56. /* /// "SelectCVIDFuncs()" */
  57. __asm void SelectCVIDFuncs(REG(a0) struct CVIDData *spec,
  58.                            REG(d0) uchar _gray,
  59.                            REG(d1) uchar _dither)
  60. {
  61.   if (_gray) {
  62.     yuv2x2_14=YUV2x2toGray;
  63.     yuv2x2_42=YUV2x2toGray;
  64.     color2x2blk1=Color2x2Blk1Gray;
  65.     color2x2blk4=Color2x2Blk4Gray;
  66.   } else if (_dither) {
  67.     yuv2x2_14=YUV2x2to332Dith14;
  68.     yuv2x2_42=YUV2x2to332Dith42;
  69.     color2x2blk1=Color2x2Blk1332Dith;
  70.     color2x2blk4=Color2x2Blk4332Dith;
  71.   } else {
  72.     yuv2x2_14=YUV2x2toRGB;
  73.     yuv2x2_42=YUV2x2toRGB;
  74.     color2x2blk1=Color2x2Blk1RGB;
  75.     color2x2blk4=Color2x2Blk4RGB;
  76.   }
  77. }
  78. /* \\\ */
  79.  
  80. /* /// "DecodeCVID()" */
  81. __asm void DecodeCVID(REG(a0) uchar *from,
  82.                       REG(a1) uchar *to,
  83.                       REG(d0) ulong width,
  84.                       REG(d1) ulong height,
  85.                       REG(d2) ulong encSize,
  86.                       REG(a2) struct CVIDData *spec)
  87. {
  88.   long x, y, cvidMapNum;
  89.   ulong len;
  90.   ulong kk, strips, cNum, yTop;
  91.  
  92.   x=0;
  93.   y=0;
  94.   yTop=0;
  95.   from++;
  96.   len=get24(from);
  97.   if (len!=encSize) {
  98.     if (len & 0x01) len++;
  99.     if (len!=encSize) return;
  100.   }
  101.   /* xsz=get16(from); ysz=get16(from); */
  102.   from+=4;
  103.   strips=get16(from);
  104.   cvidMapNum=strips;
  105.  
  106.   for (kk=0; kk<strips; kk++) {
  107.     ulong i, topCid, cid, x0, y0, x1, y1;
  108.     long topSize, cSize;
  109.     struct Color2x2 *cvidCMap0=spec->cvidMaps0[kk];
  110.     struct Color2x2 *cvidCMap1=spec->cvidMaps1[kk];
  111.     if (spec->cvidVMap0[kk]==0) {
  112.       ulong idx;
  113.       struct Color2x2 *src, *dst;
  114.       idx=(kk==0)?(strips-1):(kk-1);
  115.       src=spec->cvidMaps0[idx];
  116.       dst=spec->cvidMaps0[kk];
  117.       spec->cvidVMap0[kk]=1;
  118.       mycopymem((ulong *)&src[0],(ulong *)&dst[0],sizeof(struct Color2x2)*256); /* früher :for (i=0; i<256; i++) dst[i]=src[i] */
  119.     }
  120.     if (spec->cvidVMap1[kk]==0) {
  121.       ulong idx;
  122.       struct Color2x2 *src, *dst;
  123.       idx=(kk==0)?(strips-1):(kk-1);
  124.       src=spec->cvidMaps1[idx];
  125.       dst=spec->cvidMaps1[kk];
  126.       spec->cvidVMap1[kk]=1;
  127.       mycopymem((ulong *)&src[0],(ulong *)&dst[0],sizeof(struct Color2x2)*256); /* früher :for (i=0; i<256; i++) dst[i]=src[i] */
  128.     }
  129.     from+=2; /* topCid=get16(from); */
  130.     topSize=get16(from);
  131.     from+=4; /* y0=get16(from); x0=get16(from); */
  132.     y1=get16(from);
  133.     from+=2; /* x1=get16(from); */
  134.  
  135.     yTop+=y1;
  136.     topSize-=12;
  137.     x=0;
  138.     /* if (x1!=width) {} */
  139.     while (topSize>0) {
  140.       cid=get16(from);
  141.       cSize=get16(from);
  142.       topSize-=cSize;
  143.       cSize-=4;
  144.       switch (cid) {
  145.         case 0x2000:
  146.         case 0x2200:
  147.           { ulong i;
  148.             struct Color2x2 *cvidMap;
  149.             void __regargs (*yuv2x2) (ulong y0, ulong y1, ulong y2, ulong y3, ulong u, ulong v, struct Color2x2 *cmap2x2);
  150.             if (cid==0x2200) {
  151.               cvidMap=cvidCMap1;
  152.               for (i=0; i<cvidMapNum; i++) spec->cvidVMap1[i]=0;
  153.               spec->cvidVMap1[kk]=1;
  154.               yuv2x2=yuv2x2_14;
  155.             } else {
  156.               cvidMap=cvidCMap0;
  157.               for (i=0; i<cvidMapNum; i++) spec->cvidVMap0[i]=0;
  158.               spec->cvidVMap0[kk]=1;
  159.               yuv2x2=yuv2x2_42;
  160.             }
  161.             cNum=cSize/6;
  162.             for (i=0; i<cNum; i++) {
  163.               ulong Y0, Y1, Y2, Y3, U, V;
  164.               Y0=from[0];
  165.               Y1=from[1];
  166.               Y2=from[2];
  167.               Y3=from[3];
  168.               U=(from[4])^0x80;
  169.               V=(from[5])^0x80;
  170.               yuv2x2(Y0,Y1,Y2,Y3,U,V,cvidMap);
  171.               cvidMap++;
  172.               from+=6;
  173.             }
  174.           }
  175.           break;
  176.  
  177.         case 0x2100:
  178.         case 0x2300:
  179.           { ulong k, flag, mask;
  180.             struct Color2x2 *cvidMap;
  181.             void __regargs (*yuv2x2) (ulong y0, ulong y1, ulong y2, ulong y3, ulong u, ulong v, struct Color2x2 *cmap2x2);
  182.             if (cid==0x2300) {
  183.               cvidMap=cvidCMap1;
  184.               yuv2x2=yuv2x2_14;
  185.             } else {
  186.               cvidMap=cvidCMap0;
  187.               yuv2x2=yuv2x2_42;
  188.             }
  189.             while (cSize>0) {
  190.               flag=*(ulong *)from; from+=4; /* get32(from) */
  191.               cSize-=4;
  192.               mask=0x80000000;
  193.               while (mask) { /* for (k=0; k<32; k++) { */
  194.                 if (mask & flag) {
  195.                   ulong Y0, Y1, Y2, Y3, U, V;
  196.                   Y0=from[0];
  197.                   Y1=from[1];
  198.                   Y2=from[2];
  199.                   Y3=from[3];
  200.                   U=(from[4])^0x80;
  201.                   V=(from[5])^0x80;
  202.                   cSize-=6;
  203.                   from+=6;
  204.                   yuv2x2(Y0,Y1,Y2,Y3,U,V,cvidMap);
  205.                 }
  206.                 cvidMap++;
  207.                 mask>>=1;
  208.               }
  209.             }
  210.             /* if (cSize!=0) {} */
  211.           }
  212.           break;
  213.  
  214.         case 0x3000:
  215.           { ulong flag;
  216.             while ((cSize>0) && (y<yTop)) {
  217.               ulong mask;
  218.               long j;
  219.               flag=*(ulong *)from; from+=4; /* get32(from) */
  220.               cSize-=4;
  221.               mask=0x80000000;
  222.               while (mask) { /* for (j=0; j<32; j++) { */
  223.                 if (y>=yTop) break;
  224.                 if (mask & flag) {
  225.                   ulong d0, d1, d2, d3;
  226.                   d0=from[0];
  227.                   d1=from[1];
  228.                   d2=from[2];
  229.                   d3=from[3];
  230.                   cSize-=4;
  231.                   from+=4;
  232.                   color2x2blk4(to,x,y,width,&cvidCMap0[d0],&cvidCMap0[d1],&cvidCMap0[d2],&cvidCMap0[d3]);
  233.                 } else {
  234.                   ulong d;
  235.                   d=*from++;
  236.                   cSize--;
  237.                   color2x2blk1(to,x,y,width,&cvidCMap1[d]);
  238.                 }
  239.                 blockInc(x,y,width);
  240.                 mask>>=1;
  241.               }
  242.               if (cSize<4) {
  243.                 from+=cSize;
  244.                 cSize=0;
  245.               }
  246.             }
  247.             if (cSize) from+=cSize;
  248.           }
  249.           break;
  250.  
  251.         case 0x3200:
  252.           { while ((cSize>0) && (y<yTop)) {
  253.               ulong d;
  254.               d=*from++;
  255.               cSize--;
  256.               color2x2blk1(to,x,y,width,&cvidCMap1[d]);
  257.               blockInc(x,y,width);
  258.             }
  259.             if (cSize) from+=cSize;
  260.           }
  261.           break;
  262.  
  263.         case 0x3100:
  264.           { ulong flag, flag0, flag1, flag2;
  265.             flag1=flag2=0;
  266.             flag0=1;
  267.             while ((cSize>0) && (y<yTop)) {
  268.               ulong mCode;
  269.               long j;
  270.               flag=*(ulong *)from; from+=4; /* get32(from) */
  271.               cSize-=4;
  272.               for (j=30; j>=0; j-=2) {
  273.                 if (y>=yTop) break;
  274.                 mCode=(flag>>j) & 0x03;
  275.                 switch (mCode) {
  276.                   case 0x0:
  277.                     { flag0=1;
  278.                       if (flag1) {
  279.                         ulong d=*from++;
  280.                         flag1=0;
  281.                         cSize--;
  282.                         color2x2blk1(to,x,y,width,&cvidCMap1[d]);
  283.                       }
  284.                       blockInc(x,y,width);
  285.                     }
  286.                     break;
  287.  
  288.                   case 0x1:
  289.                     { flag1=1;
  290.                       if ((flag2) || (flag0)) {
  291.                         flag0=flag2=0;
  292.                       } else {
  293.                         ulong d=*from++;
  294.                         cSize--;
  295.                         color2x2blk1(to,x,y,width,&cvidCMap1[d]);
  296.                       }
  297.                     }
  298.                     break;
  299.  
  300.                   case 0x2:
  301.                     { flag2=1;
  302.                       if (flag1) {
  303.                         ulong d0, d1, d2, d3;
  304.                         flag1=0;
  305.                         d0=from[0];
  306.                         d1=from[1];
  307.                         d2=from[2];
  308.                         d3=from[3];
  309.                         cSize-=4;
  310.                         from+=4;
  311.                         color2x2blk4(to,x,y,width,&cvidCMap0[d0],&cvidCMap0[d1],&cvidCMap0[d2],&cvidCMap0[d3]);
  312.                         blockInc(x,y,width);
  313.                       } else {
  314.                         ulong d=*from++;
  315.                         cSize--;
  316.                         color2x2blk1(to,x,y,width,&cvidCMap1[d]);
  317.                       }
  318.                     }
  319.                     break;
  320.  
  321.                   case 0x3:
  322.                     { ulong d0, d1, d2, d3;
  323.                       d0=from[0];
  324.                       d1=from[1];
  325.                       d2=from[2];
  326.                       d3=from[3];
  327.                       cSize-=4;
  328.                       from+=4;
  329.                       color2x2blk4(to,x,y,width,&cvidCMap0[d0],&cvidCMap0[d1],&cvidCMap0[d2],&cvidCMap0[d3]);
  330.                     }
  331.                     break;
  332.                 }
  333.                 blockInc(x,y,width);
  334.               }
  335.             }
  336.             if (cSize) from+=cSize;
  337.           }
  338.           break;
  339.  
  340.         case 0x2400:
  341.         case 0x2600:
  342.           { ulong i, cNum;
  343.             struct Color2x2 *cvidMap;
  344.             if (cid==0x2600) {
  345.               cvidMap=cvidCMap1;
  346.               for (i=0; i<cvidMapNum; i++) spec->cvidVMap1[i]=0;
  347.               spec->cvidVMap1[kk]=1;
  348.             } else {
  349.               cvidMap=cvidCMap0;
  350.               for (i=0; i<cvidMapNum; i++) spec->cvidVMap0[i]=0;
  351.               spec->cvidVMap0[kk]=1;
  352.             }
  353.             if (dither) {
  354.               color2x2blk1=Color2x2Blk1Gray;
  355.               color2x2blk4=Color2x2Blk4Gray;
  356.             }
  357.             cNum=cSize/4;
  358.             for (i=0; i<cNum; i++) {
  359.               cvidMap[i].clr00=from[0];
  360.               cvidMap[i].clr10=from[1];
  361.               cvidMap[i].clr20=from[2];
  362.               cvidMap[i].clr30=from[3];
  363.               from+=4;
  364.             }
  365.           }
  366.           break;
  367.  
  368.         case 0x2500:
  369.         case 0x2700:
  370.           { ulong k, flag, mask, ci;
  371.             struct Color2x2 *cvidMap;
  372.             if (cid==0x2700)
  373.               cvidMap=cvidCMap1;
  374.             else
  375.               cvidMap=cvidCMap0;
  376.             if (dither) {
  377.               color2x2blk1=Color2x2Blk1Gray;
  378.               color2x2blk4=Color2x2Blk4Gray;
  379.             }
  380.             ci=0;
  381.             while (cSize>0) {
  382.               flag=*(ulong *)from; from+=4; /* get32(from) */
  383.               cSize-=4;
  384.               mask=0x80000000;
  385.               while (mask) { /* for (k=0; k<32; k++) { */
  386.                 if (mask & flag) {
  387.                   cvidMap[ci].clr00=from[0];
  388.                   cvidMap[ci].clr10=from[1];
  389.                   cvidMap[ci].clr20=from[2];
  390.                   cvidMap[ci].clr30=from[3];
  391.                   from+=4;
  392.                   cSize-=4;
  393.                 }
  394.                 ci++;
  395.                 mask>>=1;
  396.               }
  397.             }
  398.             /* if (cSize!=0) {} */
  399.           }
  400.           break;
  401.  
  402.         default:
  403.           return;
  404.           break;
  405.       }
  406.     }
  407.   }
  408. }
  409. /* \\\ */
  410.  
  411. /* /// "YUV2x2toRGB()" */
  412. void __regargs YUV2x2toRGB(ulong y0,
  413.                            ulong y1,
  414.                            ulong y2,
  415.                            ulong y3,
  416.                            ulong u,
  417.                            ulong v,
  418.                            struct Color2x2 *cmap2x2)
  419. {
  420.   long cr, cg, cb;
  421.  
  422.   cr=yuvTab->vrTab[v];
  423.   cg=yuvTab->ugTab[u]+yuvTab->vgTab[v];
  424.   cb=yuvTab->ubTab[u];
  425.  
  426.   YUVtoRGB(y0,cr,cg,cb,cmap2x2->rgb0);
  427.   YUVtoRGB(y1,cr,cg,cb,cmap2x2->rgb1);
  428.   YUVtoRGB(y2,cr,cg,cb,cmap2x2->rgb2);
  429.   YUVtoRGB(y3,cr,cg,cb,cmap2x2->rgb3);
  430. }
  431. /* \\\ */
  432.  
  433. /* /// "Color2x2Blk1RGB()" */
  434. void __regargs Color2x2Blk1RGB(uchar *to,
  435.                                ulong x,
  436.                                ulong y,
  437.                                ulong width,
  438.                                struct Color2x2 *cm)
  439. {
  440.   ulong rowInc=width;
  441.   RGBTriple *ip=(RGBTriple *)(to+(y*width+x)*4);
  442.  
  443.   ip[0]=cm->rgb0;
  444.   ip[1]=cm->rgb0;
  445.   ip[2]=cm->rgb1;
  446.   ip[3]=cm->rgb1;
  447.   ip+=rowInc;
  448.   ip[0]=cm->rgb0;
  449.   ip[1]=cm->rgb0;
  450.   ip[2]=cm->rgb1;
  451.   ip[3]=cm->rgb1;
  452.   ip+=rowInc;
  453.   ip[0]=cm->rgb2;
  454.   ip[1]=cm->rgb2;
  455.   ip[2]=cm->rgb3;
  456.   ip[3]=cm->rgb3;
  457.   ip+=rowInc;
  458.   ip[0]=cm->rgb2;
  459.   ip[1]=cm->rgb2;
  460.   ip[2]=cm->rgb3;
  461.   ip[3]=cm->rgb3;
  462. }
  463. /* \\\ */
  464.  
  465. /* /// "Color2x2Blk4RGB()" */
  466. void __regargs Color2x2Blk4RGB(uchar *to,
  467.                                ulong x,
  468.                                ulong y,
  469.                                ulong width,
  470.                                struct Color2x2 *cm0,
  471.                                struct Color2x2 *cm1,
  472.                                struct Color2x2 *cm2,
  473.                                struct Color2x2 *cm3)
  474. {
  475.   ulong rowInc=width;
  476.   RGBTriple *ip=(RGBTriple *)(to+(y*width+x)*4);
  477.  
  478.   ip[0]=cm0->rgb0;
  479.   ip[1]=cm0->rgb1;
  480.   ip[2]=cm1->rgb0;
  481.   ip[3]=cm1->rgb1;
  482.   ip+=rowInc;
  483.   ip[0]=cm0->rgb2;
  484.   ip[1]=cm0->rgb3;
  485.   ip[2]=cm1->rgb2;
  486.   ip[3]=cm1->rgb3;
  487.   ip+=rowInc;
  488.   ip[0]=cm2->rgb0;
  489.   ip[1]=cm2->rgb1;
  490.   ip[2]=cm3->rgb0;
  491.   ip[3]=cm3->rgb1;
  492.   ip+=rowInc;
  493.   ip[0]=cm2->rgb2;
  494.   ip[1]=cm2->rgb3;
  495.   ip[2]=cm3->rgb2;
  496.   ip[3]=cm3->rgb3;
  497. }
  498. /* \\\ */
  499.  
  500. /* /// "YUV2x2toGray()" */
  501. void __regargs YUV2x2toGray(ulong y0,
  502.                             ulong y1,
  503.                             ulong y2,
  504.                             ulong y3,
  505.                             ulong u,
  506.                             ulong v,
  507.                             struct Color2x2 *cmap2x2)
  508. {
  509.   cmap2x2->clr00=y0;
  510.   cmap2x2->clr10=y1;
  511.   cmap2x2->clr20=y2;
  512.   cmap2x2->clr30=y3;
  513. }
  514. /* \\\ */
  515.  
  516. /* /// "Color2x2Blk1Gray()" */
  517. void __regargs Color2x2Blk1Gray(uchar *to,
  518.                                 ulong x,
  519.                                 ulong y,
  520.                                 ulong width,
  521.                                 struct Color2x2 *cm)
  522. {
  523.   ulong rowInc=width;
  524.   RGBTriple *ip=(RGBTriple *)(to+(y*width+x)*4);
  525.   RGBTriple rgb0, rgb1;
  526.  
  527.   rgb0.alpha=0;
  528.   rgb1.alpha=0;
  529.   rgb0.red=rgb0.green=rgb0.blue=cm->clr00;
  530.   rgb1.red=rgb1.green=rgb1.blue=cm->clr10;
  531.   ip[0]=rgb0;
  532.   ip[1]=rgb0;
  533.   ip[2]=rgb1;
  534.   ip[3]=rgb1;
  535.   ip+=rowInc;
  536.   ip[0]=rgb0;
  537.   ip[1]=rgb0;
  538.   ip[2]=rgb1;
  539.   ip[3]=rgb1;
  540.   ip+=rowInc;
  541.   rgb0.red=rgb0.green=rgb0.blue=cm->clr20;
  542.   rgb1.red=rgb1.green=rgb1.blue=cm->clr30;
  543.   ip[0]=rgb0;
  544.   ip[1]=rgb0;
  545.   ip[2]=rgb1;
  546.   ip[3]=rgb1;
  547.   ip+=rowInc;
  548.   ip[0]=rgb0;
  549.   ip[1]=rgb0;
  550.   ip[2]=rgb1;
  551.   ip[3]=rgb1;
  552. }
  553. /* \\\ */
  554.  
  555. /* /// "Color2x2Blk4Gray()" */
  556. void __regargs Color2x2Blk4Gray(uchar *to,
  557.                                 ulong x,
  558.                                 ulong y,
  559.                                 ulong width,
  560.                                 struct Color2x2 *cm0,
  561.                                 struct Color2x2 *cm1,
  562.                                 struct Color2x2 *cm2,
  563.                                 struct Color2x2 *cm3)
  564. {
  565.   ulong rowInc=width;
  566.   RGBTriple *ip=(RGBTriple *)(to+(y*width+x)*4);
  567.   RGBTriple rgb;
  568.  
  569.   rgb.alpha=0;
  570.   rgb.red=rgb.green=rgb.blue=cm0->clr00;
  571.   ip[0]=rgb;
  572.   rgb.red=rgb.green=rgb.blue=cm0->clr10;
  573.   ip[1]=rgb;
  574.   rgb.red=rgb.green=rgb.blue=cm1->clr00;
  575.   ip[2]=rgb;
  576.   rgb.red=rgb.green=rgb.blue=cm1->clr10;
  577.   ip[3]=rgb;
  578.   ip+=rowInc;
  579.   rgb.red=rgb.green=rgb.blue=cm0->clr20;
  580.   ip[0]=rgb;
  581.   rgb.red=rgb.green=rgb.blue=cm0->clr30;
  582.   ip[1]=rgb;
  583.   rgb.red=rgb.green=rgb.blue=cm1->clr20;
  584.   ip[2]=rgb;
  585.   rgb.red=rgb.green=rgb.blue=cm1->clr30;
  586.   ip[3]=rgb;
  587.   ip+=rowInc;
  588.   rgb.red=rgb.green=rgb.blue=cm2->clr00;
  589.   ip[0]=rgb;
  590.   rgb.red=rgb.green=rgb.blue=cm2->clr10;
  591.   ip[1]=rgb;
  592.   rgb.red=rgb.green=rgb.blue=cm3->clr00;
  593.   ip[2]=rgb;
  594.   rgb.red=rgb.green=rgb.blue=cm3->clr10;
  595.   ip[3]=rgb;
  596.   ip+=rowInc;
  597.   rgb.red=rgb.green=rgb.blue=cm2->clr20;
  598.   ip[0]=rgb;
  599.   rgb.red=rgb.green=rgb.blue=cm2->clr30;
  600.   ip[1]=rgb;
  601.   rgb.red=rgb.green=rgb.blue=cm3->clr20;
  602.   ip[2]=rgb;
  603.   rgb.red=rgb.green=rgb.blue=cm3->clr30;
  604.   ip[3]=rgb;
  605. }
  606. /* \\\ */
  607.  
  608. /* /// "YUV2x2to332Dith14()" */
  609. void __regargs YUV2x2to332Dith14(ulong y0,
  610.                                  ulong y1,
  611.                                  ulong y2,
  612.                                  ulong y3,
  613.                                  ulong u,
  614.                                  ulong v,
  615.                                  struct Color2x2 *cmap2x2)
  616. {
  617.   long cr, cg, cb;
  618.   ulong clr;
  619.   long r, g, b;
  620.   long re, ge, be;
  621.   long ya, yb, yc, yd;
  622.   long yy0, yy1, yy2, yy3;
  623.  
  624.   cr=yuvTab->vrTab[v];
  625.   cg=yuvTab->ugTab[u]+yuvTab->vgTab[v];
  626.   cb=yuvTab->ubTab[u];
  627.  
  628.   yy0=(long)(yuvTab->yTab[y0]);
  629.   yy1=(long)(yuvTab->yTab[y1]);
  630.   yy2=(long)(yuvTab->yTab[y2]);
  631.   yy3=(long)(yuvTab->yTab[y3]);
  632.  
  633.   ya=yy0;
  634.   yb=(yy0+yy1) >> 1;
  635.   yc=(yy0+yy2) >> 1;
  636.   yd=(yy0+yy1+yy2+yy3) >> 2;
  637.  
  638.   dith2x2CGen(cmap2x2->clr03,yd,r,g,b,0,0,0);
  639.   dith2x2EGen(clr,r,g,b,re,ge,be);
  640.   dith2x2CGen(cmap2x2->clr02,yc,r,g,b,re,ge,be);
  641.   dith2x2EGen(clr,r,g,b,re,ge,be);
  642.   dith2x2CGen(cmap2x2->clr00,ya,r,g,b,re,ge,be);
  643.   dith2x2EGen(clr,r,g,b,re,ge,be);
  644.   dith2x2CGen(cmap2x2->clr01,yb,r,g,b,re,ge,be);
  645.  
  646.   ya=(yy1+yy0) >> 1;
  647.   yb=yy1;
  648.   yc=(yy0+yy1+yy2+yy3) >> 2;
  649.   yd=(yy1+yy3) >> 1;
  650.  
  651.   dith2x2CGen(cmap2x2->clr10,ya,r,g,b,0,0,0);
  652.   dith2x2EGen(clr,r,g,b,re,ge,be);
  653.   dith2x2CGen(cmap2x2->clr11,yb,r,g,b,re,ge,be);
  654.   dith2x2EGen(clr,r,g,b,re,ge,be);
  655.   dith2x2CGen(cmap2x2->clr13,yd,r,g,b,re,ge,be);
  656.   dith2x2EGen(clr,r,g,b,re,ge,be);
  657.   dith2x2CGen(cmap2x2->clr12,yc,r,g,b,re,ge,be);
  658.  
  659.   ya=(yy2+yy0) >> 1;
  660.   yb=(yy0+yy1+yy2+yy3) >> 2;
  661.   yc=yy2;
  662.   yd=(yy2+yy3) >> 1;
  663.  
  664.   dith2x2CGen(cmap2x2->clr20,ya,r,g,b,0,0,0);
  665.   dith2x2EGen(clr,r,g,b,re,ge,be);
  666.   dith2x2CGen(cmap2x2->clr21,yb,r,g,b,re,ge,be);
  667.   dith2x2EGen(clr,r,g,b,re,ge,be);
  668.   dith2x2CGen(cmap2x2->clr23,yd,r,g,b,re,ge,be);
  669.   dith2x2EGen(clr,r,g,b,re,ge,be);
  670.   dith2x2CGen(cmap2x2->clr22,yc,r,g,b,re,ge,be);
  671.  
  672.   ya=(yy0+yy1+yy2+yy3) >> 2;
  673.   yb=(yy3+yy1) >> 1;
  674.   yc=(yy3+yy2) >> 1;
  675.   yd=yy3;
  676.  
  677.   dith2x2CGen(cmap2x2->clr33,yd,r,g,b,0,0,0);
  678.   dith2x2EGen(clr,r,g,b,re,ge,be);
  679.   dith2x2CGen(cmap2x2->clr32,yc,r,g,b,re,ge,be);
  680.   dith2x2EGen(clr,r,g,b,re,ge,be);
  681.   dith2x2CGen(cmap2x2->clr30,ya,r,g,b,re,ge,be);
  682.   dith2x2EGen(clr,r,g,b,re,ge,be);
  683.   dith2x2CGen(cmap2x2->clr31,yb,r,g,b,re,ge,be);
  684. }
  685. /* \\\ */
  686.  
  687. /* /// "YUV2x2to332Dith42()" */
  688. void __regargs YUV2x2to332Dith42(ulong y0,
  689.                                  ulong y1,
  690.                                  ulong y2,
  691.                                  ulong y3,
  692.                                  ulong u,
  693.                                  ulong v,
  694.                                  struct Color2x2 *cmap2x2)
  695. {
  696.   long cr, cg, cb;
  697.   ulong clr;
  698.   long r, g, b;
  699.   long re, ge, be, yy;
  700.  
  701.   cr=yuvTab->vrTab[v];
  702.   cg=yuvTab->ugTab[u]+yuvTab->vgTab[v];
  703.   cb=yuvTab->ubTab[u];
  704.  
  705.   yy=(long)(yuvTab->yTab[y0]);
  706.   dith2x2CGen(cmap2x2->clr00,yy,r,g,b,0,0,0);
  707.   dith2x2EGen(clr,r,g,b,re,ge,be);
  708.   yy=(long)(yuvTab->yTab[y2]);
  709.   dith2x2CGen(cmap2x2->clr20,yy,r,g,b,re,ge,be);
  710.   dith2x2EGen(clr,r,g,b,re,ge,be);
  711.   yy=(long)(yuvTab->yTab[y3]);
  712.   dith2x2CGen(cmap2x2->clr30,yy,r,g,b,re,ge,be);
  713.   dith2x2EGen(clr,r,g,b,re,ge,be);
  714.   yy=(long)(yuvTab->yTab[y1]);
  715.   dith2x2CGen(cmap2x2->clr10,yy,r,g,b,re,ge,be);
  716.  
  717.   yy=(long)(yuvTab->yTab[y3]);
  718.   dith2x2CGen(cmap2x2->clr31,yy,r,g,b,0,0,0);
  719.   dith2x2EGen(clr,r,g,b,re,ge,be);
  720.   yy=(long)(yuvTab->yTab[y1]);
  721.   dith2x2CGen(cmap2x2->clr11,yy,r,g,b,re,ge,be);
  722.   dith2x2EGen(clr,r,g,b,re,ge,be);
  723.   yy=(long)(yuvTab->yTab[y0]);
  724.   dith2x2CGen(cmap2x2->clr01,yy,r,g,b,re,ge,be);
  725.   dith2x2EGen(clr,r,g,b,re,ge,be);
  726.   yy=(long)(yuvTab->yTab[y2]);
  727.   dith2x2CGen(cmap2x2->clr21,yy,r,g,b,re,ge,be);
  728. }
  729. /* \\\ */
  730.  
  731. /* /// "Color2x2Blk1332Dith()" */
  732. void __regargs Color2x2Blk1332Dith(uchar *to,
  733.                                    ulong x,
  734.                                    ulong y,
  735.                                    ulong width,
  736.                                    struct Color2x2 *cm)
  737. {
  738.   ulong rowInc=width;
  739.   uchar *ip=to+(y*width+x);
  740.  
  741.   ip[0]=(uchar)(cm->clr00);
  742.   ip[1]=(uchar)(cm->clr01);
  743.   ip[2]=(uchar)(cm->clr10);
  744.   ip[3]=(uchar)(cm->clr11);
  745.   ip+=rowInc;
  746.   ip[0]=(uchar)(cm->clr02);
  747.   ip[1]=(uchar)(cm->clr03);
  748.   ip[2]=(uchar)(cm->clr12);
  749.   ip[3]=(uchar)(cm->clr13);
  750.   ip+=rowInc;
  751.   ip[0]=(uchar)(cm->clr20);
  752.   ip[1]=(uchar)(cm->clr21);
  753.   ip[2]=(uchar)(cm->clr30);
  754.   ip[3]=(uchar)(cm->clr31);
  755.   ip+=rowInc;
  756.   ip[0]=(uchar)(cm->clr22);
  757.   ip[1]=(uchar)(cm->clr23);
  758.   ip[2]=(uchar)(cm->clr32);
  759.   ip[3]=(uchar)(cm->clr33);
  760. }
  761. /* \\\ */
  762.  
  763. /* /// "Color2x2Blk4332Dith()" */
  764. void __regargs Color2x2Blk4332Dith(uchar *to,
  765.                                    ulong x,
  766.                                    ulong y,
  767.                                    ulong width,
  768.                                    struct Color2x2 *cm0,
  769.                                    struct Color2x2 *cm1,
  770.                                    struct Color2x2 *cm2,
  771.                                    struct Color2x2 *cm3)
  772. {
  773.   ulong rowInc=width;
  774.   uchar *ip=to+(y*width+x);
  775.  
  776.   ip[0]=(uchar)(cm0->clr00);
  777.   ip[1]=(uchar)(cm0->clr10);
  778.   ip[2]=(uchar)(cm1->clr01);
  779.   ip[3]=(uchar)(cm1->clr11);
  780.   ip+=rowInc;
  781.   ip[0]=(uchar)(cm0->clr20);
  782.   ip[1]=(uchar)(cm0->clr30);
  783.   ip[2]=(uchar)(cm1->clr21);
  784.   ip[3]=(uchar)(cm1->clr31);
  785.   ip+=rowInc;
  786.   ip[0]=(uchar)(cm2->clr01);
  787.   ip[1]=(uchar)(cm2->clr11);
  788.   ip[2]=(uchar)(cm3->clr00);
  789.   ip[3]=(uchar)(cm3->clr10);
  790.   ip+=rowInc;
  791.   ip[0]=(uchar)(cm2->clr21);
  792.   ip[1]=(uchar)(cm2->clr31);
  793.   ip[2]=(uchar)(cm3->clr20);
  794.   ip[3]=(uchar)(cm3->clr30);
  795. }
  796. /* \\\ */
  797.  
  798.